package com.base.myproject.client.ui.selection;

import java.util.Arrays;

import com.base.myproject.client.busi.BaseStore;
import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.google.gwt.user.client.Event;
/**
 * TODO 要做一个鼠标左键按下，移动鼠标，就自动选择
 * @author zgw
 *2009-6-14 下午11:10:28
 * @param <M>
 * javazgw@gmail.com
 */
public class BaseCheckBoxSelectionModel<M extends ModelData> extends CheckBoxSelectionModel<M> {
	
	protected void handleMouseDown(GridEvent e) {

	    if ((e.getEvent().getButton() == Event.BUTTON_LEFT || e.getEvent().ONMOUSEOVER ==Event.ONMOUSEMOVE)
	        && e.getTarget().getClassName().equals("x-grid3-row-checker")) {
	      El row = e.getTarget(".x-grid3-row", 15);
	      if (row != null) {

	        M m =(M) ((BaseStore)store).getAt(e.getRowIndex());

	        if (isSelected(m)) {
	          doDeselect(Arrays.asList(m), false);
	        } else {
	          doSelect(Arrays.asList(m), true, false);
	        }
	      }
	    } else {
	      super.handleMouseDown(e);
	    }
	  }
}
